/*
 * @lc app=leetcode.cn id=283 lang=javascript
 *
 * [283] 移动零
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function (nums) {
  const swap = (nums, left, right) => {
    let temp = nums[left];
    nums[left] = nums[right];
    nums[right] = temp;
  };

  let len = nums.length,
    left = 0,
    right = 0;

  while (right < len) {
    if (nums[right] != 0) {
      swap(nums, left, right);
      left++;
    }
    right++;
  }
};
// @lc code=end
